1 Creating an R object from Spectronaut output files

[Skip for now]

filetable <-  read.table(file="/Users/shubhamagrawal/Documents/work/compressed/DIA/fileTable.txt", header = TRUE)

mae <- readExperimentDIA(fileTable = filetable, 
                         annotation_col = c("treatment", "timepoint", "replicate",
                                            "sampleType"))

2 Use the created object

mae <- readRDS("data/maeObjNEW.Rds")
mae
## A MultiAssayExperiment object of 2 listed
##  experiments with user-defined names and respective classes.
##  Containing an ExperimentList class object of length 2:
##  [1] Phosphoproteome: SummarizedExperiment with 40517 rows and 138 columns
##  [2] Proteome: SummarizedExperiment with 8518 rows and 79 columns
## Functionality:
##  experiments() - obtain the ExperimentList instance
##  colData() - the primary/phenotype DataFrame
##  sampleMap() - the sample coordination DataFrame
##  `$`, `[`, `[[` - extract colData columns, subset, or experiment
##  *Format() - convert into a long or wide DataFrame
##  assays() - convert ExperimentList to a SimpleList of matrices
##  exportClass() - save data to flat files

3 Preprocessing the assay, basic visualization, PCA

se <- mae[["Phosphoproteome"]]
colData(se) <- colData(mae[, colnames(se)])
se
## class: SummarizedExperiment 
## dim: 40517 138 
## metadata(0):
## assays(1): Intensity
## rownames(40517): s1 s2 ... s40516 s40517
## rowData names(6): UniprotID Gene ... Sequence site
## colnames(138): FullProteome_1stCtrl_0min_rep2
##   FullProteome_1stCtrl_0min_rep3 ... Phospho_HGF_40min_rep1
##   Phospho_HGF_6h_rep1
## colData names(6): treatment timepoint ... sample sampleName
plotIntensity(se[, se$sampleType == "Phospho"], color = "replicate") + theme_classic() +
  theme(
    axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0, size = 7),
    plot.title = element_text(hjust = 0.5, face = "bold")
  ) 

newSE <- preprocessPhos(seData = se, transform = "log2", 
                        normalize = TRUE, impute = "QRILC")
## Warning in fun(libname, pkgname): mzR has been built against a different Rcpp version (1.0.12)
## than is installed on your system (1.1.0). This might lead to errors
## when loading mzR. If you encounter such issues, please send a report,
## including the output of sessionInfo() to the Bioc support forum at 
## https://support.bioconductor.org/. For details see also
## https://github.com/sneumann/mzR/wiki/mzR-Rcpp-compiler-linker-issue.
## Imputing along margin 2 (samples/columns).
newSE
## class: SummarizedExperiment 
## dim: 13081 59 
## metadata(0):
## assays(2): Intensity imputed
## rownames(13081): s1 s4 ... s40511 s40514
## rowData names(6): UniprotID Gene ... Sequence site
## colnames(59): Phospho_1stCtrl_0min_rep2 Phospho_1stCtrl_0min_rep3 ...
##   Phospho_HGF_40min_rep1 Phospho_HGF_6h_rep1
## colData names(6): treatment timepoint ... sample sampleName
plotIntensity(newSE, color = "replicate") + theme_classic() +
  theme(
    axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0, size = 7),
    plot.title = element_text(hjust = 0.5, face = "bold")
  ) 

plotMissing(newSE) + theme_classic() +
  theme(
    axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0, size = 7),
    plot.title = element_text(hjust = 0.5, face = "bold")
  ) 

4 Perform PCA

pca <- stats::prcomp(t(assays(newSE)[["imputed"]]), center = TRUE, scale. = TRUE)
p <- plotPCA(pca = pca, se = newSE,
             color = "treatment",
             shape = "replicate")

p$layers[[1]]$aes_params$size   <- 3
p$layers[[1]]$aes_params$stroke <- 1.2

p + coord_equal() + theme(aspect.ratio = 1, legend.position = "right",
                          axis.text = element_text(color = "#000000")) +
  guides(
    shape = guide_legend(order = 1),
    color = guide_legend(order = 2)
    )

5 rep1 samples need to be removed or perform batch correction

newSE <- preprocessPhos(seData = se, transform = "log2", 
                        normalize = TRUE, impute = "QRILC", 
                        removeOutlier = "rep1")
## Imputing along margin 2 (samples/columns).
newSE
## class: SummarizedExperiment 
## dim: 17035 32 
## metadata(0):
## assays(2): Intensity imputed
## rownames(17035): s1 s4 ... s40513 s40514
## rowData names(6): UniprotID Gene ... Sequence site
## colnames(32): Phospho_1stCtrl_0min_rep2 Phospho_1stCtrl_0min_rep3 ...
##   Phospho_HGF_40min_rep2 Phospho_HGF_40min_rep3
## colData names(6): treatment timepoint ... sample sampleName
pca <- stats::prcomp(t(assays(newSE)[["imputed"]]), 
                     center = TRUE, scale. = TRUE)
p <- plotPCA(pca = pca, se = newSE,
             color = "treatment",
             shape = "replicate")

p$layers[[1]]$aes_params$size   <- 3
p$layers[[1]]$aes_params$stroke <- 1.2

p + coord_equal() + theme(aspect.ratio = 1, legend.position = "right",
                          axis.text = element_text(color = "#000000")) +
  guides(
    shape = guide_legend(order = 1),
    color = guide_legend(order = 2)
    )

p <- plotHeatmap(type = "Top variant", newSE, top = 30, annotationCol = c("replicate", "treatment")) 

g <- p$gtable

# Find row names grob
row_names <- which(g$layout$name == "row_names")
g$grobs[[row_names]]$gp <- gpar(fontsize = 8, fontface = "bold")
# Same for columns
col_names <- which(g$layout$name == "col_names")
g$grobs[[col_names]]$gp <- gpar(fontsize = 10)

grid.newpage()
grid.draw(g)

6 Differential expression

dea <- performDifferentialExp(se = newSE, 
                              assay = "imputed", 
                              method = "limma", 
                              condition = "treatment", 
                              reference = "1stCtrl", 
                              target = "H.E")
p <- ggplot(dea$resDE, aes(x = pvalue)) +
  geom_histogram(fill = "grey", col = "blue", alpha=0.7) +
  ggtitle("P value histogram") + theme_classic() +
  theme(plot.title = element_text(hjust = 0.5)) 
  
p
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

pFilter = 0.01
plotVolcano(dea$resDE, pFilter = 0.01, fcFilter = 1) + theme_classic() +
  geom_hline(yintercept = -log10(as.numeric(pFilter)), color = "brown",
               linetype = "dashed") +
    annotate(x = 3.0, y = -log10(as.numeric(pFilter)) - 0.20,
             label = paste0("P-value = ", as.numeric(pFilter)),
             geom = "text", size = 3.5, color = "brown") 

plotVolcanoDEA(dea$resDE, fcFilter = 1, pFilter = 0.01, usePadj = FALSE)

dea$resDE
## # A tibble: 17,035 × 11
##    ID    log2FC  stat   pvalue    padj UniprotID Gene  Position Residue Sequence
##    <I<c>  <dbl> <dbl>    <dbl>   <dbl> <chr>     <chr> <chr>    <chr>   <chr>   
##  1 s176…  -3.50 -35.2 1.13e-12 1.92e-8 Q3MIN7    RGL3  573      S       PAGSPPA…
##  2 s2851   8.40  27.4 1.70e-11 1.08e-7 O60885    BRD4  470      S       EPVVAVS…
##  3 s128…   7.12  27.1 1.91e-11 1.08e-7 Q06124    PTPN… 580      Y       REDSARV…
##  4 s4880   8.35  22.1 1.72e-10 7.32e-7 O95870    ABHD… 32       T       APASVPE…
##  5 s398…   6.86  20.7 3.61e-10 1.21e-6 Q9Y4K1    CRYB… 363      T       SSAQADC…
##  6 s129…   3.33  20.4 4.25e-10 1.21e-6 Q07889    SOS1  1134     S       PHGPRSA…
##  7 s5284   2.69  19.7 6.13e-10 1.34e-6 P04920    SLC4… 243      S       QERRRIG…
##  8 s383…   6.82  19.6 6.28e-10 1.34e-6 Q9UPY5    SLC7… 26       S       NVNGRLP…
##  9 s582   -2.29 -19.0 8.77e-10 1.58e-6 O00401    WASL  256      Y       RETSKVI…
## 10 s668    2.58  18.9 9.56e-10 1.58e-6 O00515    LAD1  38       S       RRRHRNL…
## # ℹ 17,025 more rows
## # ℹ 1 more variable: site <chr>
intensityBoxPlot(se = dea$seSub, id = 's4971', symbol = "EGFR_S991")

7 Time series clustering

set.seed(12345)

newSEts <- newSE[ , newSE$treatment == "H.E"]
assayMat <- SummarizedExperiment::assay(newSEts)

exprMat <- lapply(unique(newSEts$timepoint), function(tp) {
  rowMedians(assayMat[,newSEts$timepoint == tp])
  }) %>% bind_cols() %>% as.matrix()
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
rownames(exprMat) <- rownames(newSEts)
colnames(exprMat) <- unique(newSEts$timepoint)

sds <- apply(exprMat,1,sd)
varPer <- 80
exprMat <- exprMat[order(sds, decreasing = TRUE)[seq(1, varPer/100*nrow(exprMat))], ]
# only center when it's for expression
exprMat <- mscale(exprMat)
# remove NA values
exprMat <- exprMat[complete.cases(exprMat), ]


tsc <- clusterTS(x = exprMat, k = 5, pCut = 0.6)
tsc$plot + theme(
  axis.text.x = element_text(size = 10), axis.text = element_text(color = "#000000"), ) 

8 Enrichment analysis

genesetPath <- system.file("shiny-app/geneset", package = "SmartPhos")
inGMT1 <- piano::loadGSC(paste0(genesetPath, "/Cancer_Hallmark.gmt"), 
                         type="gmt")
resTab <- enrichDifferential(dea = dea$resDE, type = "Pathway enrichment", 
                             gsaMethod = "PAGE", geneSet = inGMT1, 
                             statType = "stat", nPerm = 200, sigLevel = 0.05, 
                             ifFDR = FALSE)
## Running gene set analysis:
## Checking arguments...done!
## Final gene/gene-set association: 1218 genes and 50 gene sets
##   Details:
##   Calculating gene set statistics from 1218 out of 4183 gene-level statistics
##   Removed 3168 genes from GSC due to lack of matching gene statistics
##   Removed 0 gene sets containing no genes after gene removal
##   Removed additionally 0 gene sets not matching the size limits
##   Loaded additional information for 50 gene sets
## Calculating gene set statistics...done!
## Calculating gene set significance...done!
## Adjusting for multiple testing...done!
resTab
##                                         Name Gene Number    Stat      p.up
## 1                   HALLMARK_MITOTIC_SPINDLE         145  2.6658 0.0038407
## 2                    HALLMARK_APICAL_SURFACE          10  1.7214 0.0425930
## 3                    HALLMARK_MYC_TARGETS_V1         112 -1.6775 0.9532800
## 4                        HALLMARK_MYOGENESIS          43 -1.7676 0.9614300
## 5 HALLMARK_EPITHELIAL_MESENCHYMAL_TRANSITION          29 -1.9409 0.9738700
## 6                    HALLMARK_G2M_CHECKPOINT         116 -2.0758 0.9810400
## 7                 HALLMARK_KRAS_SIGNALING_DN          14 -2.5684 0.9948900
## 8                HALLMARK_HEDGEHOG_SIGNALING          10 -3.1079 0.9990600
##   p.up.adj     p.down p.down.adj Number up Number down
## 1  0.19203 0.99616000   0.996160        83          62
## 2  0.99906 0.95741000   0.976950         7           3
## 3  0.99906 0.04672300   0.389360        53          59
## 4  0.99906 0.03856600   0.385660        17          26
## 5  0.99906 0.02613400   0.326670         9          20
## 6  0.99906 0.01895800   0.315970        50          66
## 7  0.99906 0.00510840   0.127710         2          12
## 8  0.99906 0.00094225   0.047112         1           9
inGMT2 <- piano::loadGSC(paste0(genesetPath, "/KEGG_pathways.gmt"), 
                         type="gmt")
clustEnr <- clusterEnrich(clusterTab = tsc$cluster, se = newSE, 
                          inputSet = inGMT2, filterP = 0.01, ifFDR = FALSE)
clustEnr$plot + theme_classic()

9 Kinase activity inference

First on the differential expression analysis results

netw <- getDecouplerNetwork("Homo sapiens")
scoreTab <- calcKinaseScore(dea$resDE, netw, statType = "stat", nPerm = 100)
plotKinaseDE(scoreTab, nTop = 10, pCut = 0.05)

clusterData <- tsc$cluster[tsc$cluster$cluster == "cluster1",]
allClusterFeature <- clusterData %>%
  distinct(feature, .keep_all = TRUE) %>% .$feature
allClusterSite <- data.frame(rowData(newSEts)[allClusterFeature, "site"])
allClusterSite$feature <- allClusterFeature
clusterData <- clusterData %>%
  left_join(allClusterSite, by = "feature") %>%
  rename(site = "rowData.newSEts..allClusterFeature...site..")
scoreTab <- calcKinaseScore(clusterData, netw, statType = "stat", nPerm = 100)
plotKinaseTimeSeries(scoreTab, pCut = 0.05, clusterName = "cluster1")

10 Phosphosites pattern

newSEts <- addZeroTime(newSE, condition = "treatment", treat = "H.E", 
                       zeroTreat = "1stCtrl", 
                       timeRange = c("20min","40min","100min"))

rd <- as.data.frame(rowData(newSEts))
timerange <- unique(newSEts$timepoint)
sites <-  c("MET_Y1234",  "MET_Y1235", "MET_1003", "Shc1_Y427", "AKT3_Y312", "RPS6KB1", "EGFR_Y1092", "EGFR_Y1172", "SOS1_S1134", "MAP2K2_S226", "MAPK3_T202", "MAPK1_T190", "EGFR_Y1197", "ERBB2_S998","GAB1_Y659","RPS6_S244")

for (i in sites) {
  # condition to check if that site is present in row data
  if (i %in% rd$site) {
    # condition to check if assay doesn't have NAs (imputed assays are not allowed)
    if (!is.na(assay(newSEts)[rownames(rd[rd$site==i,]), ][1])) {
      p <- plotTimeSeries(newSEts, type = "expression", 
                        geneID = rownames(rd[rd$site==i,]), 
                        symbol = i, condition = "treatment", 
                        treatment = "H.E", timerange = timerange) +
        theme(axis.text = element_text(color = "#000000", size = 20), 
              axis.text.x = element_text(angle = 0, vjust = 0, hjust = 0.5, size = 20),
              axis.title = element_text(size=20),
              plot.title = element_text(size=30)) +
        scale_x_continuous(breaks = c(0,20,40,60,80,100))
      p$layers[[1]]$aes_params$size <- 6
      p$layers[[1]]$mapping$colour <- NULL
      p$layers[[1]]$aes_params$colour <- "#c1191f"
      p$layers[[2]]$aes_params$linewidth <- 1
      p$layers[[2]]$mapping$colour <- NULL
      p$layers[[2]]$aes_params$colour <- "#555555"
      print(p)
    }
  }
}